package 笔试;

import java.util.Arrays;
import java.util.HashMap;

public class 腾讯音乐_字符串操作 {
    public static int minOperations (String str) {
        // write code here
        char[] arr = str.toCharArray();
        Arrays.sort(arr);
        HashMap<Character, Integer> map = new HashMap<>();

        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            map.put(arr[i], map.getOrDefault(arr[i],0)+1);
        }
        int p = 0;

        int tmp1 = 0;
        for (int i = 0; i < arr.length; i++) {
            if(map.get(arr[i]) >= 2) {
                if(arr[i] != tmp1 && map.get(arr[i]) % 2 == 1) {
                    map.put(arr[i],map.get(arr[i])-1);
                    int tmp = map.get(arr[i]);
                    while(tmp > 0) {
                        tmp -= 2;
                        count++;
                    }
                    tmp1 = arr[i];
                } else if(arr[i] != tmp1){
                    int tmp = map.get(arr[i]);
                    while(tmp > 0) {
                        tmp -= 2;
                        count++;
                    }
                    tmp1 = arr[i];
                }
            } else {
                continue;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        String s = "abab";
        int res = minOperations(s);
        System.out.println(res);
    }
}
